home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PCGUIA 117
/
PC Guia 117.iso
/
Software
/
Utils
/
Software6
/
Product13
/
googlebar-0.9.5.06-fx.xpi
/
chrome
/
googlebar.jar
/
content
/
googlebarOverlay.js
< prev
next >
Wrap
Text File
|
2005-02-21
|
123KB
|
3,543 lines
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Googlebar for Mozilla.
*
* The Initial Developer of the Original Code is Andy Edmonds.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Andy Boughton
* Andrew Houghton
* John Woods
* Bernd Kuemmerlen
* Robert Mulcahy
* Alfred Kayser
* Reflex
* Gary Turnbull
* Raj Bhaskar
* Joachim Thewes
* Henrik Gemal
* Robert Fernandes
* Joe Chellman
* Franki Cheung
* Alban Fonrouge
* Martin Hassman
* Ufuk Kayserilioglu
* Yoni Gilad
* Tim Schmidt
* timeless
* Francis Turner
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// ****************************
// * BEGIN NEWLY REFACTORED *
// ****************************
// ****************************************
// * CONSTANTS - SERVICES, OBJECTS, ETC *
// ****************************************
const GB_DRAG_SVC = Components.classes["@mozilla.org/widget/dragservice;1"].getService(Components.interfaces.nsIDragService);
const GB_PREF_SVC = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
const GB_PROMPT_SVC = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
const GB_WINDOW_SVC = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
const GB_FIND_OBJ = Components.classes['@mozilla.org/embedcomp/rangefind;1'].createInstance().QueryInterface(Components.interfaces.nsIFind);
const GB_ROOT_OBJ = GB_PREF_SVC.getBranch(null);
const GB_PREF_OBJ = GB_PREF_SVC.getBranch("googlebar.");
const GB_URL_OBJ = Components.classes["@mozilla.org/network/standard-url;1"].createInstance().QueryInterface(Components.interfaces.nsIURL);
try {
const GB_STRING_FLAG = "nsISupportsWString" in Components.interfaces && Components.interfaces.nsISupportsWString || "nsISupportsString" in Components.interfaces && Components.interfaces.nsISupportsString;
const GB_STRING_CONSTRUCTOR = Components.Constructor("@mozilla.org/supports-wstring;1" in Components.classes && Components.classes["@mozilla.org/supports-wstring;1"] || "@mozilla.org/supports-string;1" in Components.classes && Components.classes["@mozilla.org/supports-string;1"], GB_STRING_FLAG);
}
catch (e) {
myGooglebarUtil.logMessage("Problem creating string objects " + e);
}
// ******************************
// * LOCATION LISTENER OBJECT *
// ******************************
var myGooglebarLocListener =
{
QueryInterface: function(aIID) {
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onProgressChange: function (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {},
onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {},
onSecurityChange: function(aWebProgress, aRequest, aState) {},
onLinkIconAvailable: function(a) {},
onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) {
if(aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP) {
if (myGooglebarHighlight.isHighlightOn()) {
myGooglebarHighlight.highLightInPage("on");
}
}
},
onLocationChange: function(aWebProgress, aRequest, aLocation) {
if (aLocation) {
var url = aLocation.spec;
var terms;
// Old (broken) tests
//if(/^http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*q=([^&]*)&.*/i.test(url))
//if(/^http:\/\/[^\.]*\.google\..*?\/[^\?]*?\?.*?q=([^&]*)/i.test(url))
// Test to see if the URL matches the given pattern
if (/^http:\/\/[^\.]*?\.google\..*?\/[^\?]*?\?.*?q=([^&]*)&.*/i.test(url)) {
terms = RegExp.$1;
terms = terms.replace(/\+?(site|cache):[^\+]*\+?/g, "");
terms = terms.replace(/\+/g, " ");
terms = terms.replace(/\#.*$/g, "");
terms = decodeURIComponent(terms);
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
critBox.value = terms;
googlebarCheckSearchbuttons();
}
else {
googlebarUpdateNewWindow();
googlebarCheckSearchbuttons();
}
var siteBtn = myGooglebarUtil.getElement("site-separate");
if (/^\s*http:\/\/[^\.]*\.google\..*\/.*/i.test(url)) {
if (/^\s*http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*q=site:([^&]*)(&.*)*/i.test(url)) {
siteBtn.setAttribute("disabled", false);
}
else {
siteBtn.setAttribute("disabled", true);
}
}
else {
siteBtn.setAttribute("disabled", false);
}
// This block of code was put in to update the navigation list when location
// changes, even when not using the navigation items. This may or may not
// be the desired behavior. To remove this functionality the entire marked
// block of code can just simply be replaced with a single line:
//
// googlebarLoadResults();
//
// That's it.
// Begin Update Navigation Block
var inResult = false;
for (var i = 0; i < lastResults.length; i++) {
if (url == lastResults[i]) {
setTimeout("googlebarCheckNavigation(" + i + ")", 100);
inResult = true;
break;
}
}
if (!inResult) {
googlebarLoadResults();
}
// End Update Navigation Block
updateUp();
}
}
};
// ********************************
// * PREFERENCE OBSERVER OBJECT *
// ********************************
var myGooglebarPrefObserver = {
register: function() {
if (!GB_PREF_OBJ) {
return;
}
var pbi = GB_PREF_OBJ.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
pbi.addObserver("", this, false);
},
unregister: function() {
if (!GB_PREF_OBJ) {
return;
}
var pbi = GB_PREF_OBJ.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
pbi.removeObserver("", this);
},
observe: function(aSubject, aTopic, aData) {
// aSubject is the nsIPrefBranch being observed
if (aTopic != "nsPref:changed") {
return;
}
switch (aData) {
case "contextmenuoption":
myGooglebarUtil.logMessage("contextmenuoption pref changed");
break;
case "updateColors":
myGooglebarUtil.logMessage("updateColors pref changed");
break;
default:
myGooglebarUtil.logMessage("unknown pref changed -- not paying attention to " + aData + " preference");
break;
}
}
};
myGooglebarPrefObserver.register();
// ****************************
// * END NEWLY REFACTORED *
// ****************************
var altAction, altCtrlAction, altShiftAction, ctrlAction, ctrlShiftAction, noneAction, shiftAction;
var altLocation, altCtrlLocation, altShiftLocation, ctrlLocation, ctrlShiftLocation, noneLocation, shiftLocation;
var boolCritSelected, ggb_loaded, win, hkeytgl, srch4SelAppnd, googlebarRemoveNow;
var loading = boolCritSelected = ggb_loaded = win = hkeytgl = srch4SelAppnd = googlebarRemoveNow = false;
var openerUpdated = false;
var critIgnoreFocus = false;
var critIgnoreClick = false;
var populateUniv = false;
var n = 0;
var term = '';
var arrDeckActs = [
"default", "site", "lucky", "groups", "directory", "images", "news",
"USA", "Catalog", "dictionary", "glossary", "mac", "bsd", "linux",
"microsoft", "webquotes", "viewer", "stocks", "froogle", "university",
"nocalc", "gb-mycountry", "gb-mylocal", "gblogger", "scholar", "answers"
];
var arrDeckLocs = [
"Same Window", "New Tab", "New Window"
];
var cntrySfxs = new Array(99);
var cntry2Srch, cntry2SrchIx;
var mycntrySfxs = new Array(69);
var mycntry2Srch, mycntry2SrchIx;
var mylangSfxs = new Array(37);
var mylang2Srch, mylang2SrchIx;
var cntryNewsSfxs = new Array(10);
var cntryNews2Srch, cntryNews2SrchIx;
var cntryNewsSites = new Array(10);
var cntryNewsSite;
var gbmycountryPref ;
var gbmylocalString = "";
var gbmylocalPref = "";
// country domain override - for features like translate which need to use the USA site
var onlyInUSA = "com";
// the option flags that we are going to save search history across browser sessions
var autoSearchOption = false;
var historyOption = true;
var historyLoaded = false;
var maxHistCnt;
var sep = "||";
// the option value for how many results are listed from a search
var resultLimit;
var autoSelectOption = true;
var saveLastOption = false;
var hideMenuOption = false;
var queryStringOption = false;
var sortByDate = false;
// hidden prefs should have a spot so here is the first one.
var gbloggerStandardWinPref ;
// Remember the last focused element for stateful toggling
var gStatefulPrevFocus = null;
// Array for storing last Google search results
// (used by back/fwd result navigation stuff)
var lastResultIndx = -99;
var lastResults = new Array(0);
var lastResultPages = new Array(0);
var lastGoogle = null;
var university = null;
var universityName = null;
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// Init //////////////////////////////////////
function googlebarDisplayCheck()
{
// make sure that we are loading the preferences
googlebarInitPrefs();
if (!historyLoaded) {
historyLoaded = true;
if (historyOption) {
googlebarInitHistory();
}
else {
GB_PREF_OBJ.setCharPref("history", "");
}
}
myGooglebarHighlight.displayCheck();
if (populateUniv) {
reallyUpdateUniv();
}
googlebarLoadResults();
googlebarUpdateCriteriaDropmarker();
}
function googlebarUpdateCriteriaDropmarker(inPrefs)
{
if (inPrefs) {
historyOption = myGooglebarUtil.getElement("historyoption").checked;
}
var critMenu = myGooglebarUtil.getElement("googlebarCriteria");
if (!critMenu) {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.googlebarUpdateCriteriaDropmarker.1"));
}
else {
var critMenuDrop = myGooglebarUtil.getAnonymousElement(critMenu, "class", "menulist-dropmarker");
critMenuDrop.setAttribute("hidden", !historyOption);
}
// clear the history when it was switched off
if (!historyOption) {
googlebarClearHistory( false ); // and clear the critBox
}
}
function googlebarInitCustom()
{
var customArray = new Array();
try {
var string = GB_PREF_OBJ.getComplexValue("customList", GB_STRING_FLAG).data;
customArray = string.split(sep);
googlebarUpdateCustomList(customArray);
}
catch(e) {
myGooglebarUtil.logMessage("\Custom list init failure caught\n" + e);
}
}
function googlebarInitHistory()
{
var historyArray = new Array();
try {
var string = GB_PREF_OBJ.getComplexValue("history", GB_STRING_FLAG).data;
historyArray = string.split(sep);
}
catch(e) {
myGooglebarUtil.logMessage("\nHistory init failure caught\n" + e);
}
// iterate over the saved history items and add them to the list
// and make sure to use the second paramenter of the addToHistory
// function so that we don't add it to the saved preference again
for (var i = 0; i < historyArray.length; i++) {
if (historyArray[i]) {
googlebarAddToHistory(historyArray[i], true);
}
}
}
function googlebarInitPrefs()
{
// this is a leftover from the early days.
// We used to use a try googlebarReadPref and catch the missing pref failures
// here, and set them. Then the prefs grewup and they now have their own try
// catch blocks for each pref. The way it was done before was ok, for a few
// prefs. If you add a pref, the be sure to add it to both Firefox and Seamonkey
// user interfaces. googlebarPrefDialog.xul
googlebarReadPref();
}
function googlebarReadPref()
{
/***********************************
Modifier Key Action Preferences
***********************************/
try {
altAction = GB_PREF_OBJ.getCharPref("ActionAlt");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("ActionAlt", "0"); // Default
altAction = GB_PREF_OBJ.getCharPref("ActionAlt");
}
try {
altCtrlAction = GB_PREF_OBJ.getCharPref("ActionAltCtrl");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("ActionAltCtrl", "0"); // Default
altCtrlAction = GB_PREF_OBJ.getCharPref("ActionAltCtrl");
}
try {
altShiftAction = GB_PREF_OBJ.getCharPref("ActionAltShift");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("ActionAltShift", "0"); // Default
altShiftAction = GB_PREF_OBJ.getCharPref("ActionAltShift");
}
try {
ctrlAction = GB_PREF_OBJ.getCharPref("ActionCtrl");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("ActionCtrl", "0"); // Default
ctrlAction = GB_PREF_OBJ.getCharPref("ActionCtrl");
}
try {
ctrlShiftAction = GB_PREF_OBJ.getCharPref("ActionCtrlShift");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("ActionCtrlShift", "0"); // Default
ctrlShiftAction = GB_PREF_OBJ.getCharPref("ActionCtrlShift");
}
try {
noneAction = GB_PREF_OBJ.getCharPref("ActionNone");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("ActionNone", "0"); // Default
noneAction = GB_PREF_OBJ.getCharPref("ActionNone");
}
try {
shiftAction = GB_PREF_OBJ.getCharPref("ActionShift");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("ActionShift", "0"); // Default
shiftAction = GB_PREF_OBJ.getCharPref("ActionShift");
}
/*************************************
Modifier Key Location Preferences
*************************************/
try {
altLocation = GB_PREF_OBJ.getCharPref("LocationAlt");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("LocationAlt", "0"); // Same Window
altLocation = GB_PREF_OBJ.getCharPref("LocationAlt");
}
try {
altCtrlLocation = GB_PREF_OBJ.getCharPref("LocationAltCtrl");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("LocationAltCtrl", "0"); // Same Window
altCtrlLocation = GB_PREF_OBJ.getCharPref("LocationAltCtrl");
}
try {
altShiftLocation = GB_PREF_OBJ.getCharPref("LocationAltShift");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("LocationAltShift", "0"); // Same Window
altShiftLocation = GB_PREF_OBJ.getCharPref("LocationAltShift");
}
try {
ctrlLocation = GB_PREF_OBJ.getCharPref("LocationCtrl");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("LocationCtrl", "1"); // New Tab
ctrlLocation = GB_PREF_OBJ.getCharPref("LocationCtrl");
}
try {
ctrlShiftLocation = GB_PREF_OBJ.getCharPref("LocationCtrlShift");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("LocationCtrlShift", "1"); // New Tab
ctrlShiftLocation = GB_PREF_OBJ.getCharPref("LocationCtrlShift");
}
try {
noneLocation = GB_PREF_OBJ.getCharPref("LocationNone");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("LocationNone", "0"); // Same Window
noneLocation = GB_PREF_OBJ.getCharPref("LocationNone");
}
try {
shiftLocation = GB_PREF_OBJ.getCharPref("LocationShift");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("LocationShift", "2"); // New Window
shiftLocation = GB_PREF_OBJ.getCharPref("LocationShift");
}
/****************************************
Domain Specific Preferences (Search)
****************************************/
try {
cntry2SrchIx = GB_PREF_OBJ.getIntPref("country2Search");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setIntPref("country2Search", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country_default"));
cntry2SrchIx = GB_PREF_OBJ.getIntPref("country2Search");
}
cntrySfxsInit();
cntry2Srch = cntrySfxs[cntry2SrchIx];
// &cr=countryUK
try {
mycntry2SrchIx = GB_PREF_OBJ.getIntPref("mycountry2Search");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setIntPref("mycountry2Search", 0 ); // cr=countryUS
mycntry2SrchIx = GB_PREF_OBJ.getIntPref("mycountry2Search");
}
mycntrySfxsInit();
mycntry2Srch = mycntrySfxs[mycntry2SrchIx];
// &lr=lang_en
try {
mylang2SrchIx = GB_PREF_OBJ.getIntPref("mylang2Search");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setIntPref("mylang2Search", 0 ); // lr=en
mylang2SrchIx = GB_PREF_OBJ.getIntPref("mylang2Search");
}
mylangSfxsInit();
mylang2Srch = mylangSfxs[mylang2SrchIx];
/**************************************
Domain Specific Preferences (News)
**************************************/
try {
cntryNews2SrchIx = GB_PREF_OBJ.getIntPref("countryNews2Search");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setIntPref("countryNews2Search", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country_default"));
cntryNews2SrchIx = GB_PREF_OBJ.getIntPref("countryNews2Search");
}
cntryNewsSfxsInit();
cntryNews2Srch = cntryNewsSfxs[cntryNews2SrchIx];
cntryNewsSite = cntryNewsSites[cntryNews2SrchIx];
/***********************************
Other Miscellaneous Preferences
***********************************/
try {
autoSearchOption = GB_PREF_OBJ.getBoolPref("autosearchoption");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("autosearchoption", false); // Auto Search When History Item Selected
autoSearchOption = GB_PREF_OBJ.getBoolPref("autosearchoption");
}
try {
cntxtmnuopt = GB_PREF_OBJ.getBoolPref("contextmenuoption");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("contextmenuoption", true);
cntxtmnuopt = GB_PREF_OBJ.getBoolPref("contextmenuoption");
}
try {
hideMenuOption = GB_PREF_OBJ.getBoolPref("hidemenuoption");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("hidemenuoption", false); // Hide Menu Items Promoted to Buttons
hideMenuOption = GB_PREF_OBJ.getBoolPref("hidemenuoption");
}
try {
historyOption = GB_PREF_OBJ.getBoolPref("historyoption");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("historyoption", true); // Save History
GB_PREF_OBJ.setCharPref("history", "googlebar"); // History Value
historyOption = GB_PREF_OBJ.getBoolPref("historyoption");
}
try {
hkeytgl = GB_PREF_OBJ.getBoolPref("hotkeySelectionToggles");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("hotkeySelectionToggles", false); // mimic ctrl-L or toggle
hkeytgl = GB_PREF_OBJ.getBoolPref("hotkeySelectionToggles");
}
try {
srch4SelAppnd = GB_PREF_OBJ.getBoolPref("search4SelectedAppends");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("search4SelectedAppends", false); // replace or append text
srch4SelAppnd = GB_PREF_OBJ.getBoolPref("search4SelectedAppends");
}
/*
try {
labsOption = GB_PREF_OBJ.getBoolPref("searchoption");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("searchoption", false); // Google Labs
labsOption = GB_PREF_OBJ.getBoolPref("searchoption");
}
*/
try {
maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setIntPref("maxHistCnt", 10); // Maximum History Values Kept
maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
}
try {
queryStringOption = GB_PREF_OBJ.getBoolPref("querystringoption");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("querystringoption", false); // Ignore Query String for Up Dir Button
queryStringOption = GB_PREF_OBJ.getBoolPref("querystringoption");
}
try {
autoSelectOption = GB_PREF_OBJ.getBoolPref("autoselectoption");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("autoselectoption", true); // Auto Select Search Term Criteria
autoSelectOption = GB_PREF_OBJ.getBoolPref("autoselectoption");
}
try {
saveLastOption = GB_PREF_OBJ.getBoolPref("savelastoption");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("savelastoption", false); // Save Last Search Type
saveLastOption = GB_PREF_OBJ.getBoolPref("savelastoption");
}
try {
sortByDate = GB_PREF_OBJ.getBoolPref("sortByDate");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setBoolPref("sortByDate", false); // Sort Google Search Results by Date
sortByDate = GB_PREF_OBJ.getBoolPref("sortByDate");
}
try {
resultLimit = GB_PREF_OBJ.getIntPref("resultLimit");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setIntPref("resultLimit", -1); // Number of Results to Return - Negative value ignored
resultLimit = GB_PREF_OBJ.getIntPref("resultLimit");
}
// If there was a previous university selected
// then use that as the default, otherwise just
// ignore it
try {
university = GB_PREF_OBJ.getCharPref("university");
universityName = GB_PREF_OBJ.getCharPref("universityName");
setUniv(university, universityName);
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref("university","");
GB_PREF_OBJ.setCharPref("universityName","");
university = GB_PREF_OBJ.getCharPref("university");
universityName = GB_PREF_OBJ.getCharPref("universityName");
}
try {
var showLabels = GB_PREF_OBJ.getBoolPref("showLabels");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
myGooglebarUtil.logMessage('Resetting label pref');
GB_PREF_OBJ.setBoolPref("showLabels", false); // Show Toolbar Button Labels
}
myGooglebarUtil.getElement("LabelsButtonItem").setAttribute("checked", GB_PREF_OBJ.getBoolPref("showLabels"));
googlebarLabels();
try {
var lockOrdinals = GB_PREF_OBJ.getBoolPref("lockOrdinals");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
myGooglebarUtil.logMessage('Resetting ordinal pref');
GB_PREF_OBJ.setBoolPref("lockOrdinals", true); // Lock Toolbar Button Positions
}
myGooglebarUtil.getElement("OrderLockButtonItem").setAttribute("checked", GB_PREF_OBJ.getBoolPref("lockOrdinals"));
googlebarOrdinals();
/*************************************
Experimental Preferences
*************************************/
try {
var googleSuggest = GB_PREF_OBJ.getBoolPref("googleSuggest");
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
myGooglebarUtil.logMessage('Resetting Google Suggest pref');
GB_PREF_OBJ.setBoolPref("googleSuggest", false); // Use Google Suggest
}
try {
ggb_init();
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
}
setGoogleContextMenu();
if (myGooglebarUtil.isInFirefox()) {
// workaround bug 6171
try {
historyOption = GB_PREF_OBJ.getBoolPref("historyoption");
maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
if(historyOption == "false") {
GB_PREF_OBJ.setIntPref("maxHistCnt", 0);
maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
}
}
catch(e) {
myGooglebarUtil.logMessage( e );
}
// end workaround bug 6171
}
myGooglebarUtil.logMessage("Finished ReadPrefs OK\n");
}
function ggb_init()
{
if (!ggb_loaded) {
window.removeEventListener("keypress",googlebarDisplayCheck,true);
window.removeEventListener("mousemove",googlebarDisplayCheck,true);
ggb_loaded = true;
if (!myGooglebarUtil.isInFirefox()){
check4NewInstall();
}
window.getBrowser().addProgressListener(myGooglebarLocListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
window.getBrowser().addProgressListener(myGooglebarLocListener, Components.interfaces.nsIWebProgress.STATE_STOP);
var hideExtras = !(myGooglebarUtil.getElement("extras-box").childNodes.length > 0);
myGooglebarUtil.getElement("extras-box").setAttribute("hidden", hideExtras);
myGooglebarUtil.getElement("ExtrasButtonItem").setAttribute("hidden", hideExtras);
myGooglebarUtil.getElement("LabelsButtonItem").addEventListener("DOMAttrModified", ggb_LabelListener, false);
myGooglebarUtil.getElement("OrderLockButtonItem").addEventListener("DOMAttrModified", ggb_OrdinalListener, false);
if (myGooglebarUtil.isInFirefox()){
myGooglebarUtil.getElement("gb-prefill-separate").setAttribute("hidden", true);
myGooglebarUtil.getElement("gb-prefillButtonItem").setAttribute("hidden", true);
}
googlebarSyncMenuButton("comp-menu", "lastCompSearch");
googlebarSyncMenuButton("cust-menu", "lastCustSearch");
googlebarSyncMenuButton("info-menu", "lastInfoSearch");
googlebarSyncMenuButton("spec-menu", "lastSpecSearch");
googlebarGoPopupMenus();
initCustomOrder(); // this function is actually in googlebarDragAndDrop.js
googlebarInitCustom();
// Try to put the hide/show menuitem under the toolbar popup
var toolbarContainer = myGooglebarUtil.getElement("menu_viewPopup");
var toolbarPopup;
if (toolbarContainer != null)
{
for (var i = 0; i < toolbarContainer.childNodes.length; i++) {
if ( toolbarContainer.childNodes.item(i).nodeName == "menu"
&& toolbarContainer.childNodes.item(i).getAttribute("label") == "Toolbars")
{
toolbarPopup = toolbarContainer.childNodes.item(i).getElementsByTagName("menupopup").item(0);
}
}
var tempNode = document.createElement("menuitem");
tempNode.setAttribute("id", "view_gg_menuitem");
tempNode.setAttribute("label", "Googlebar");
tempNode.setAttribute("class", "menuitem-iconic");
tempNode.setAttribute("type", "checkbox");
tempNode.setAttribute("key", "key_googlebarShowHide");
tempNode.setAttribute("observes", "cmd_googlebarShowHide");
tempNode.setAttribute("accesskey", "G");
if (toolbarPopup != null)
{
toolbarPopup.appendChild(document.createElement("menuseparator"));
toolbarPopup.appendChild(tempNode);
}
else
{
toolbarContainer.appendChild(tempNode);
}
}
myGooglebarUtil.logMessage('Initialized googlebar');
}
else {
googlebarGoPopupMenus();
updateUp();
}
}
function ggb_LabelListener(e) {
if (e && e.attrName == 'checked') {
GB_PREF_OBJ.setBoolPref("showLabels", e.newValue == "true");
googlebarLabels();
}
}
function ggb_OrdinalListener(e) {
if (e && e.attrName == 'checked') {
GB_PREF_OBJ.setBoolPref("lockOrdinals", e.newValue == "true");
googlebarOrdinals();
}
}
function googlebarCustomNavigation()
{
if (!window._content.document) {
return;
}
var url = window._content.document.location;
var doc = window._content.document.documentElement;
var aElems = doc.getElementsByTagName("A");
var curr, last;
var i = 0;
var count = 0;
// Don't retrieve back to back duplicate links
for (i = 0; i < aElems.length; i++) {
curr = getAnchorURL(aElems[i], url)
if (curr && last != curr) {
last = curr;
count++;
}
}
if (count > 0) {
lastResults = new Array(count);
}
else {
lastResults = new Array(0);
googlebarCheckNavigation(-99);
return;
}
count = 0;
for (i = 0; i < aElems.length; i++) {
curr = getAnchorURL(aElems[i], url);
if (curr && last != curr) {
last = curr;
lastResults[count] = curr;
count++;
}
}
// also populate the last google result and set up the button appropriately
lastGoogle = url;
var lastBtn = myGooglebarUtil.getElement("last-button");
var lastBtnPop = myGooglebarUtil.getElement("last-button-popup");
lastBtn.removeAttribute("oncommand");
lastBtn.setAttribute("disabled", false);
lastBtn.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
// clean up all of the popup menu items
for (i = lastBtnPop.childNodes.length - 1; i >= 0; i--) {
lastBtnPop.removeChild(lastBtnPop.childNodes[i]);
}
setTimeout("googlebarCheckNavigation(-1)", 100);
}
function getAnchorURL(element, baseURL)
{
var href = element.getAttribute("href");
var url;
if (!href || /^\s*mailto:/i.test(href)) {
return null;
}
else {
GB_URL_OBJ.spec = baseURL;
url = GB_URL_OBJ.resolve(href);
}
if (url) {
return url;
}
else {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.getAnchorURL.1") + "\n" + href);
return null;
}
}
function googlebarLoadResults()
{
if (!window._content.document) {
return;
}
var url = window._content.document.location;
if (/^\s*http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*q=([^&]*)(&.*)*/i.test(url)) {
// Must have just loaded a google query result page
// so lets repopulate the array of last results.
//
// In a Google query result page all of the results
// are under HTML paragraph elements "P" with a class
// attribute of "g". The first URL (child element "A")
// is the actual result that we care about.
var doc = window._content.document.documentElement;
var pElems = doc.getElementsByTagName("P");
var aElems;
var i = 0;
var count = 0;
for (i = 0; i < pElems.length; i++) {
if (pElems[i].getAttribute("class") == "g") {
count++;
}
}
if (count > 0) {
lastResults = new Array(count);
}
else {
lastResults = new Array(0);
return;
}
count = 0;
for (i = 0; i < pElems.length; i++) {
if (pElems[i].getAttribute("class") == "g") {
aElems = pElems[i].getElementsByTagName("A");
if (aElems.length > 0) {
lastResults[count] = aElems[0].getAttribute("href");
}
count++;
}
}
// also populate the last google result and set up the button appropriately
lastGoogle = url;
var lastBtn = myGooglebarUtil.getElement("last-button");
var lastBtnPop = myGooglebarUtil.getElement("last-button-popup");
lastBtn.removeAttribute("oncommand");
lastBtn.setAttribute("disabled", false);
lastBtn.setAttribute("onclick", "if (event.button == 1) { navGoMenu(event, '" + url + "', -1); event.preventBubble(); }");
lastBtn.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
// clean up all of the popup menu items
for (i = lastBtnPop.childNodes.length - 1; i >= 0; i--) {
lastBtnPop.removeChild(lastBtnPop.childNodes[i]);
}
var divElems = doc.getElementsByTagName("div");
var divElem;
for (i = 0; i < divElems.length; i++) {
if (divElems[i].getAttribute("class") == "n") {
divElem = divElems[i];
break;
}
}
if (divElem) {
var urlRoot = url.toString().substring(0, url.toString().lastIndexOf("/"));
var imgElems = divElem.getElementsByTagName("img");
var imgSrc;
var page;
var tempNode;
for (i = 0; i < imgElems.length; i++) {
imgSrc = imgElems[i].getAttribute("src");
if (imgSrc.indexOf("nav_previous") >= 0) {
url = urlRoot + imgElems[i].parentNode.getAttribute("href");
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", "Previous Result Page");
tempNode.setAttribute("tooltiptext", "Previous Result Page");
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
lastBtnPop.appendChild(tempNode);
lastBtnPop.appendChild(document.createElement("menuseparator"));
}
else if (imgSrc.indexOf("nav_current") >= 0) {
url = lastGoogle;
page = imgElems[i].parentNode.getElementsByTagName("span")[0].firstChild.nodeValue;
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", "Result Page " + page);
tempNode.setAttribute("tooltiptext", "Result Page " + page);
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("type", "checkbox");
tempNode.setAttribute("checked", "true");
tempNode.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
lastBtnPop.appendChild(tempNode);
}
else if (imgSrc.indexOf("nav_page") >= 0) {
url = urlRoot + imgElems[i].parentNode.getAttribute("href");
page = imgElems[i].parentNode.childNodes[2].nodeValue;
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", "Result Page " + page);
tempNode.setAttribute("tooltiptext", "Result Page " + page);
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
lastBtnPop.appendChild(tempNode);
}
else if (imgSrc.indexOf("nav_next") >= 0) {
url = urlRoot + imgElems[i].parentNode.getAttribute("href");
lastBtnPop.appendChild(document.createElement("menuseparator"));
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", "Next Result Page");
tempNode.setAttribute("tooltiptext", "Next Result Page");
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
lastBtnPop.appendChild(tempNode);
}
}
}
setTimeout("googlebarCheckNavigation(-1)", 100);
}
}
function googlebarCheckNavigation(resultIndx)
{
if (!window._content.document) {
return;
}
var prevBtn = myGooglebarUtil.getElement("prev-button");
var nextBtn = myGooglebarUtil.getElement("next-button");
var prevBtnPop = myGooglebarUtil.getElement("prev-button-popup");
var nextBtnPop = myGooglebarUtil.getElement("next-button-popup");
var ndx;
// clean up all of the popup menu items
for (ndx = prevBtnPop.childNodes.length - 1; ndx >= 0; ndx--) {
prevBtnPop.removeChild(prevBtnPop.childNodes[ndx]);
}
for (ndx = nextBtnPop.childNodes.length - 1; ndx >= 0; ndx--) {
nextBtnPop.removeChild(nextBtnPop.childNodes[ndx]);
}
// if we didn't find a match then disable both buttons and return
if (resultIndx == null || resultIndx < -1) {
prevBtn.setAttribute("disabled", true);
prevBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.prev.tooltip"));
nextBtn.setAttribute("disabled", true);
nextBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.next.tooltip"));
return;
}
/*
else if (lastResultIndx == resultIndx) {
return;
}
*/
else {
lastResultIndx = resultIndx;
}
// the oncommand attribute must be REMOVED because if
// the button is disabled it should take no action and
// if it is already set you can't just set it again,
// for some reason that has no effect so you have to
// remove the attribute and add it again
// prevBtn.removeAttribute("oncommand");
// nextBtn.removeAttribute("oncommand");
var loc;
var tempNode;
// previous navigation
if (lastResultIndx <= 0) {
prevBtn.setAttribute("disabled", true);
prevBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.prev.tooltip"));
}
else {
ndx = lastResultIndx - 1;
loc = lastResults[ndx];
prevBtn.setAttribute("disabled", false);
prevBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.prev.tooltip") + " - " + loc);
prevBtn.setAttribute("oncommand", "navGo(event, 'prev-button-popup');");
for (ndx = lastResultIndx - 1; ndx >= 0; ndx--) {
loc = lastResults[ndx];
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", (ndx + 1) + " - " + loc);
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "navGoMenu(event, '" + loc + "', " + ndx + "); event.preventBubble();");
tempNode.setAttribute("nav-loc", loc);
tempNode.setAttribute("nav-ndx", ndx);
prevBtnPop.appendChild(tempNode);
}
}
// next navigation
if (lastResultIndx == lastResults.length - 1) {
nextBtn.setAttribute("disabled", true);
nextBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.next.tooltip"));
}
else {
ndx = lastResultIndx + 1;
loc = lastResults[ndx];
nextBtn.setAttribute("disabled", false);
nextBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.next.tooltip") + " - " + loc);
nextBtn.setAttribute("oncommand", "navGo(event, 'next-button-popup');");
for (ndx = lastResultIndx + 1; ndx < lastResults.length; ndx++) {
loc = lastResults[ndx];
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", (ndx + 1) + " - " + loc);
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "navGoMenu(event, '" + loc + "', " + ndx + "); event.preventBubble();");
tempNode.setAttribute("nav-loc", loc);
tempNode.setAttribute("nav-ndx", ndx);
nextBtnPop.appendChild(tempNode);
}
}
}
function navGo(event, source)
{
var navContainer = myGooglebarUtil.getElement(source);
if (navContainer && navContainer.getElementsByTagName("menuitem").length > 0) {
var tempNode = navContainer.getElementsByTagName("menuitem")[0];
navGoMenu(event, tempNode.getAttribute("nav-loc"), parseInt(tempNode.getAttribute("nav-ndx")));
}
}
function navGoMenu(event, addy, resultIndx)
{
googlebarDoAction(addy, googlebarGetLocFromEvent(event));
setTimeout("googlebarCheckNavigation(" + resultIndx + ")", 100);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Main Search /////////////////////////////////
function googlebarAutoSearch(event)
{
googlebarInitPrefs();
if (autoSearchOption) {
googlebarSearch(event);
}
}
function googlebarSearch(event, searchType, searchParams)
{
var win = window._content.document;
var searchURL;
// recover any pref changes like country and modifiers immediately
googlebarInitPrefs();
if (!searchType) {
searchType = googlebarGetActFromEvent(event);
}
// Some things cannot be done in a new tab, such as formfilling and capturing.
// bailing out beforehand
if(searchParams == "NO_SEARCH") {
if(gbDoNonSearch(event, searchType, searchParams));
return; // we are already done
}
if( gbLook4URL(event, searchType, searchParams)) {
// hold on and let the user beware of what they put in here
// we will get more on this
// FIX ME need to escape illegal characters
searchType = "doUrlNav" ;
}
if (!loading) {
googlebarClearTerms();
var critVal = myGooglebarUtil.trimString(myGooglebarUtil.getElement("googlebarCriteria").value);
var noCriteria = true;
if (critVal != "")
{
noCriteria = false;
googlebarAddTerm(critVal);
googlebarAddToHistory(critVal);
}
var crit = googlebarBuildURI(critVal);
switch(searchType) {
// TODO: Figure out which cases might not want to be searched if there is no search criteria
case "site":
if (noCriteria)
return;
var searchHost;
// If you are on a site search result then reuse that site for the next search,
// otherwise use the current window location shown in the browser
if (/^\s*http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*q=site:([^\+]*)([^&]*)(&.*)*/i.test(win.location.href)) {
searchHost = RegExp.$1;
}
else {
searchHost = win.location.hostname;
}
searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=site:' + searchHost + '+' + crit;
break;
case "backwards":
searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&q=link:' + googlebarInfoLocation();
break;
case "similar":
searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&q=related:' + googlebarInfoLocation();
break;
case "translate":
searchURL = 'http://translate.google.' + onlyInUSA + '/translate?sourceid=mozclient&u=' + googlebarInfoLocation();
break;
case "cachelink":
if (!searchParams) {
searchParams = 'http://www.google.com/';
}
searchURL = 'http://www.google.' + cntry2Srch + '/search?q=cache:' + searchParams;
break;
case "cache":
searchURL = 'http://www.google.' + cntry2Srch + '/search?q=cache:' + googlebarInfoLocation();
break;
case "images":
if (noCriteria)
searchURL = 'http://images.google.' + cntry2Srch + '/';
else
searchURL = 'http://images.google.' + cntry2Srch + '/images?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit;
break;
case "groups":
if (noCriteria)
searchURL = 'http://groups.google.' + cntry2Srch + '/';
else
searchURL = 'http://groups.google.' + cntry2Srch + '/groups?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit;
break;
case "directory":
if (noCriteria)
return;
searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit + '&cat=gwd/Top&sa=N&tab=gd';
break;
case "lucky":
if (noCriteria)
return;
searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit + '&btnI=I%27m+Feeling+Lucky';
break;
case "scholar":
if (noCriteria)
searchURL = 'http://scholar.google.' + onlyInUSA + '/';
else
searchURL = 'http://scholar.google.' + onlyInUSA + '/scholar?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit;
break;
case "USA":
if (noCriteria)
searchURL = 'http://www.google.' + onlyInUSA + '/unclesam';
else
searchURL = 'http://www.google.' + onlyInUSA + '/unclesam?sourceid=mozclient&restrict=unclesam&ie=utf-8&oe=utf-8&q=' + crit;
break;
case "Catalog":
if (noCriteria)
searchURL = 'http://catalogs.google.' + onlyInUSA + '/';
else
searchURL = 'http://catalogs.google.' + onlyInUSA + '/catalogs?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit;
break;
case "bsd":
if (noCriteria)
searchURL = 'http://www.google.' + cntry2Srch + '/bsd';
else
searchURL = 'http://www.google.' + cntry2Srch + '/bsd?restrict=bsd&ie=utf-8&oe=utf-8&q=' + crit;
break;
case "microsoft":
if (noCriteria)
searchURL = 'http://www.google.' + cntry2Srch + '/microsoft';
else
searchURL = 'http://www.google.' + cntry2Srch + '/microsoft?sourceid=mozclient&hq=microsoft&restrict=microsoft&ie=utf-8&oe=utf-8&q=' + crit;
break;
case "mac":
if (noCriteria)
searchURL = 'http://www.google.' + cntry2Srch + '/mac';
else
searchURL = 'http://www.google.' + cntry2Srch + '/mac?sourceid=mozclient&restrict=mac&ie=utf-8&oe=utf-8&q=' + crit;
break;
case "linux":
if (noCriteria)
searchURL = 'http://www.google.' + cntry2Srch + '/linux';
else
searchURL = 'http://www.google.' + cntry2Srch + '/linux?sourceid=mozclient&restrict=linux&ie=utf-8&oe=utf-8&q=' + crit;
break;
case "news":
if (noCriteria)
searchURL = googlebarNewsLocation();
else
searchURL = 'http://news.google.' + onlyInUSA + '/news?sourceid=mozclient&ie=utf-8&oe=utf-8&' + cntryNews2Srch + '&q=' + crit;
break;
case "answers":
if (noCriteria)
searchURL = 'http://answers.google.' + onlyInUSA + '/';
else
searchURL = 'http://answers.google.' + onlyInUSA + '/answers/main?cmd=search&qtype=all&q=' + crit;
break;
case "webquotes":
if (noCriteria)
return;
searchURL = 'http://labs.google.' + onlyInUSA + '/cgi-bin/webquotes?num_quotes=3&q=' + crit + '&btnG=Google+WebQuotes+Search&show_titles=1&bold_links=1&snippet_threshold=3&ie=utf-8&oe=utf-8';
break;
case "stocks":
if (noCriteria)
return;
searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=stocks:' + crit;
break;
case "viewer":
if (noCriteria)
return;
searchURL = 'http://labs1.google.' + onlyInUSA + '/cgi-bin/gviewer.cgi?q=' +crit + '&btnG=Google+Search&ie=utf-8&oe=utf-8';
break;
case "froogle":
if (noCriteria)
searchURL = 'http://froogle.google.' + onlyInUSA + '/';
else
searchURL = 'http://froogle.google.' + onlyInUSA + '/froogle?q=' + crit + '&btnG=Froogle+Search&ie=utf-8&oe=utf-8';
break;
case "dictionary":
if (noCriteria)
searchURL = 'http://www.dictionary.com/';
else
searchURL = 'http://www.dictionary.com/cgi-bin/dict.pl?term=' + crit;
break;
case "glossary":
if (noCriteria)
return;
// searchURL = 'http://labs.google.' + cntry2Srch + '/glossary?q=' + crit;
// Glossary search doesn't appear to be valid for countries outside the US
// searchURL = 'http://labs.google.' + onlyInUSA + '/glossary?q=' + crit;
searchURL = 'http://www.google.' + onlyInUSA + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=define:' + crit;
break;
case "gb-mycountry":
if (noCriteria)
return;
searchURL = 'http://www.google.' + cntry2Srch + '/search?&cr=' + mycntry2Srch + '&lr=' + mylang2Srch + '&q=' + crit ;
break;
// XXX
case "gb-mylocal":
var s1 = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.gbmylocal.msg");
var s2 = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.gbmylocal.initial");
var s3 = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.gbmylocal.title");
try {
gbmylocalString = GB_PREF_OBJ.getCharPref("gbmylocalPref");
}
catch(e) {
myGooglebarUtil.logMessage( "\n" + e + "\n" );
//msg, initial, parent, title
//returns user input through initial
gbmylocalString=gbprompt( s1, s2, window, s3);
if(gbmylocalString)
GB_PREF_OBJ.setCharPref("gbmylocalPref", gbmylocalString); // Default
else
GB_PREF_OBJ.setCharPref("gbmylocalPref", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mylocalPrefDef" ));
gbmylocalString = GB_PREF_OBJ.getCharPref("gbmylocalPref");
}
// shift and middle mousebutton
if(event.shiftKey && searchParams == "REPROGRAM" ) {
gbmylocalString=gbprompt( s1, gbmylocalString, window, s3);
if(gbmylocalString)
GB_PREF_OBJ.setCharPref("gbmylocalPref", gbmylocalString); // Default
else
GB_PREF_OBJ.setCharPref("gbmylocalPref", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mylocalPrefDef" ));
}
if(gbmylocalString) {
searchURL = 'http://local.google.' + cntry2Srch + '/local?&near=' + gbmylocalString + '&q=' + crit + '&btnG=Google+Search&ie=utf-8&oe=utf-8';
break;
}
else
return;
case "gblogger":
// do not put mozclient in... else sort by date will mess this one up.
// var gbloggerStandardWinPref ;
try {
gbloggerStandardWinPref = GB_PREF_OBJ.getBoolPref("gbloggerStandardWinPref");
}
catch(e) {
gbloggerStandardWinPref = false;
GB_PREF_OBJ.setBoolPref("gbloggerStandardWinPref", true );
myGooglebarUtil.logMessage("\n***Gblogger error\n" + e + "\n");
}
if( gbloggerStandardWinPref ){
var Q='';
var x=window._content; // was document, moz complains;
var y=window._content;
if(x.selection){Q=x.selection.createRange().text;}
else if(y.getSelection){Q=y.getSelection();}
else if(x.getSelection){Q=x.getSelection();}
// void(window.open('http://www.blogger.com/blog_this.pyra?t='+escape(Q)+'&u='+escape(location.href)+'&n='+escape(document.title)));
void(window.open('http://www.blogger.com/blog_this.pyra?t='+escape(Q)+'&u='+escape(x.location.href)+'&n='+escape(x.document.title),'bloggerForm','scrollbars=no,width=475,height=300,top=175,left=75,status=yes,resizable=yes'));
return;
}
else {
Q="";
x=window._content; // .document;
y=window._content;
if(x.selection) //this is deprecated, I haven't seen it true yet either
{Q=x.selection.createRange().text;}
else
if(y.getSelection)
{Q=y.getSelection();}
else
if(x.getSelection)
{Q=x.getSelection();}
searchURL = 'http://www.blogger.' + onlyInUSA + '/blog_this.pyra?t='+escape(Q)+'&u='+escape(x.location.href)+'&n='+escape(x.document.title) ;
}
break;
case "university":
if (!university) {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.univ.none"));
return;
}
if (noCriteria) {
searchURL = university;
}
else if (universityName == "All Universities") {
searchURL = university + '&q=' + crit;
}
else {
searchURL = university + '?q=' + crit;
}
break;
case "nocalc":
if (noCriteria)
return;
searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=%2B' + crit + '&nocalc=1';
break;
case "doUrlNav":
searchURL = myGooglebarUtil.getElement("googlebarCriteria").value;
break;
default:
/*
if (labsOption) {
searchURL = 'http://labs.google.com/cgi-bin/keys?q=';
}
else {
searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=';
}
*/
searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=';
searchURL += crit;
break;
}
if (sortByDate) {
searchURL = searchURL.replace('sourceid=mozclient','sourceid=mozclient&scoring=d');
}
if (resultLimit > 0) {
searchURL = searchURL.replace('sourceid=mozclient','sourceid=mozclient&num=' + resultLimit);
}
googlebarDoAction(searchURL, googlebarGetLocFromEvent(event));
}
}
function googlebarGetLocFromEvent(event)
{
// alert("ALT : " + event.altKey + "\nCTRL : " + event.ctrlKey + "\nSHIFT : " + event.shiftKey + "\n");
if (event.button == 1) {
return "New Tab";
}
if (event.altKey) {
if (event.ctrlKey) {
return arrDeckLocs[altCtrlLocation];
}
else if (event.shiftKey) {
return arrDeckLocs[altShiftLocation];
}
else {
return arrDeckLocs[altLocation];
}
}
else if (event.ctrlKey) {
if (event.shiftKey) {
return arrDeckLocs[ctrlShiftLocation];
}
else {
return arrDeckLocs[ctrlLocation];
}
}
else if (event.shiftKey) {
return arrDeckLocs[shiftLocation];
}
else {
return arrDeckLocs[noneLocation];
}
}
function googlebarGetActFromEvent(event)
{
if (event.altKey) {
if (event.ctrlKey) {
return arrDeckActs[altCtrlAction];
}
else if (event.shiftKey) {
return arrDeckActs[altShiftAction];
}
else {
return arrDeckActs[altAction];
}
}
else if (event.ctrlKey) {
if (event.shiftKey) {
return arrDeckActs[ctrlShiftAction];
}
else {
return arrDeckActs[ctrlAction];
}
}
else if (event.shiftKey) {
return arrDeckActs[shiftAction];
}
else {
return arrDeckActs[noneAction];
}
}
function googlebarInfoLocation()
{
var win = window._content.document;
var location;
if (/^\s*http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*(q=link:|q=related:|q=site:|u=)([^\+]*)([^&]*)(&.*)*/i.test(win.location.href)) {
location = RegExp.$2;
}
else if (/^\s*http:\/\/.*\/[^\?]*\?.*q=cache:([^\+]*)([^&]*)(&.*)*/i.test(win.location.href)) {
location = RegExp.$1;
}
else {
location = win.location;
}
return escape(location);
}
function googlebarNewsLocation()
{
var location = 'http://news.google.' + onlyInUSA + cntryNewsSite;
return location;
}
function googlebarDoAction(searchURL, location)
{
switch(location) {
case "Same Window":
window._content.document.location = searchURL;
// if we are using google labs for the search, then we
// want to make sure that we return the focus to the
// main navigator window
/*
if (labsOption) {
window.frames[0].focus();
}
else {
window.content.focus();
}
*/
window.content.focus();
break;
case "New Tab":
var browser = getBrowser();
var tab = browser.addTab(searchURL, getReferrer(document));
window.content.focus();
// Hook this up -- have we init'ed GB_ROOT_OBJ
//if (!GB_ROOT_OBJ.getBoolPref("browser.tabs.loadInBackground")) {
if (!GB_ROOT_OBJ.getBoolPref("browser.tabs.loadBookmarksInBackground")) {
browser.selectedTab = tab;
}
break;
case "New Window":
window.open(searchURL);
break;
default:
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.error"));
break;
}
}
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// Support ///////////////////////////////////
function googlebarEscape(term)
{
// we need to handle both '/' and '+' specially
term = encodeURIComponent(term);
return term.replace(/\+/g,"%2B").replace(/\//g,"%2F");
}
function googlebarBuildURI(criteria)
{
var terms = criteria.split(" ");
var uri = "";
for (var i = 0; i < terms.length; i++) {
if (i > 0) {
uri += "+";
}
uri += googlebarEscape(terms[i]);
}
return uri;
}
function googlebarPaste(event)
{
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
var textBox;
// attempt to grab selected text from the current document (tab)
var text = _content.document.getSelection();
// if nothing selected in the document then perhaps there is a
// selection contained within a frame of the current document
if (!text) {
for (var i = 0; i < _content.frames.length; i++) {
text = _content.frames[i].document.getSelection();
if (text) break;
}
}
// if still no text has been found then perhaps something in
// the the location text box has been selected
if (!text) {
textBox = window.document.getElementById("urlbar");
if (textBox.selectionStart >= 0) {
text = textBox.value.substring(textBox.selectionStart, textBox.selectionEnd);
}
}
// if still no text has been found then perhaps something in
// the the criteria box has been selected - not sure why you
// would want to search on something already in the criteria
// box but hey, who am I to criticize
// hmmm, here is a far fetched use case so I'll leave this code
// for now - someone may have multiple terms in the criteria
// box and may want to only search on one of them, highlighting
// that single term and then shift+click on highlight search
// button would search on that term alone - not likely, but a use case
if (!text) {
textBox = myGooglebarUtil.getElement("googlebarCriteria");
if (textBox.selectionStart >= 0) {
text = textBox.value.substring(textBox.selectionStart, textBox.selectionEnd);
}
}
// if we have found some selected text then set the criteria
// box to that value and reset the search term buttons,
// otherwise display an error message via an alert
if (text) {
// if there was no previous text or the shift key was pressed
// then change the value to the selected text, otherwise append
// the text to the end of what was already there. after that
// then the search term buttons need to be updated
if (!critBox.value){
critBox.value = text;
}
else
{
if(event.shiftKey) {
srch4SelAppnd ? critBox.value = text : critBox.value += " " + text;
}
else {
srch4SelAppnd ? critBox.value += " " + text : critBox.value = text;
}
}
var savedPref;
try {
// Just sneak in a pref change for this
// one search and reset it when done.
// better have this already!!
savedPref = noneLocation ;
GB_PREF_OBJ.setCharPref("LocationNone", "1"); // New Tab
// New text in box, so update the buttons...
googlebarCheckSearchbuttons();
// Do it.
if(srch4SelAppnd == event.shiftKey)
googlebarSearch(event);
GB_PREF_OBJ.setCharPref("LocationNone", savedPref);
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
myGooglebarUtil.logMessage("\nCouldn't set LocationNone pref for googlebarPaste\n");
}
}
else {
// Still NO text!!!
// Now we'll look for forms input boxes
// yes, try and get the text
// no, emit our default nothing selected msg early on!!!
var formsArray = content.document.forms;
if (!formsArray) {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.select_before"));
return;
}
var form;
for (form=0; form<formsArray.length; form++) {
var elementsArray = formsArray[form].elements;
var element;
for (element=0; element < elementsArray.length; element++) {
var type = elementsArray[element].type;
if ((type=="text") || (type=="textarea")) {
if( elementsArray[element].selectionStart != elementsArray[element].selectionEnd) {
// stuffit into our criteriaBox
text = elementsArray[element].value.substring(elementsArray[element].selectionStart, elementsArray[element].selectionEnd);
critBox.value = text;
try {
// Just sneak in a pref change for this
// one search and reset it when done.
// could call it like this but...
// GB_PREF_OBJ.getCharPref("LocationNone");
// better have this already!!
savedPref = noneLocation ;
GB_PREF_OBJ.setCharPref("LocationNone", "1"); // New Tab as default
// New text in box, so update the buttons...
googlebarCheckSearchbuttons();
// Do it
googlebarSearch(event);
GB_PREF_OBJ.setCharPref("LocationNone", savedPref);
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
myGooglebarUtil.logMessage("\nCouldn't set LocationNone pref for googlebarPaste\n");
}
} // Selection start and end are different
} // ((type=="") || (type=="text") || (type=="input"))
} // for (element=0; element < elementsArray.length; element++)
} // for (form=0; form<formsArray.length; form++)
} // else
}
function googlebarFindTerms(criteria)
{
// quotes only matter when preceded by a space or a quote.
var terms = new Array();
var val, testIndx, spaceIndx;
var tempval = criteria;
var inQuote = false;
var haveTerm = false;
var currPtr = 0; // the start of the current term
var prevChar = ' '; // the char we last saw
// JW. I have little experience with this function but what was there would only handle one word.
// So I hope this doesn't break things.
try { testIndx = tempval.search(/(cache|link|related|stocks|define|site|allintitle|intitle|allinurl|inurl|filetype|group):/g); }
catch(e){ } // nothing
if (testIndx >= 0) {
spaceIndx = tempval.indexOf(" ");
if (spaceIndx >= 0 && spaceIndx < testIndx)
criteria = tempval.slice(0, testIndx);
else
criteria = "";
criteria += tempval.slice(1 + tempval.indexOf(":"), tempval.length);
}
for (var index = 0; index < criteria.length; index++) {
var currChar = criteria.charAt(index);
switch (currChar) {
case ' ':
// case '+':
case '(':
case ')':
case '~':
// these characters do not occur on the search term buttons,
// except in quoted phrases
if (!inQuote && haveTerm) {
val = myGooglebarUtil.trimString(criteria.substring(currPtr, index));
if (!myGooglebarUtil.inArray(terms, val)) {
if (val != 'OR' && val[0] != '-') {
terms.push(val);
}
}
haveTerm = false;
}
break;
case '"':
// phrases (enclosed in "") should result in only one button
if (!inQuote) {
if (haveTerm) {
val = myGooglebarUtil.trimString(criteria.substring(currPtr, index));
if (!myGooglebarUtil.inArray(terms, val)) {
terms.push(val);
}
haveTerm = false;
}
// any of the discardable characters can occur before a phrase
if ((prevChar == ' ')
|| (prevChar == '"')
|| (prevChar == '(')
|| (prevChar == ')')
|| (prevChar == '+')
|| (prevChar == '~')
) {
inQuote = true;
}
}
else {
if (haveTerm) {
val = /*myGooglebarUtil.trimString(*/criteria.substring(currPtr, index)/*)*/;
if (!myGooglebarUtil.inArray(terms, val)) {
terms.push(val);
}
haveTerm = false;
inQuote = false;
}
}
break;
default:
if (!haveTerm) {
haveTerm = true;
currPtr = index;
}
}
prevChar = currChar;
}
val = myGooglebarUtil.trimString(criteria.substring(currPtr, index));
// FIX ME this only gets executed on the last term in a group
// I'll leave it for now. jw.
if (haveTerm && !myGooglebarUtil.inArray(terms, val) ) {
// remove special prefixes
val = val.replace(/(cache|link|related|stocks|define|site|allintitle|intitle|allinurl|inurl|filetype|group):/,'');
if (val != 'OR' && val[0] != '-') {
terms.push(val);
}
}
return terms;
}
function googlebarAddToHistory(term, ignorePref)
{
// This function adds the string "term" to the search
// history *only* if it is not already there
// Robert, we should probably remove the term from it's location in the list,
// and then put it at the top of the list. My favorite terms roll off the list,
// even when I use them frequently. waddya think? jw
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
var historyMenu = critBox.childNodes.item(0);
var numHistItems = historyMenu.childNodes.length;
var alreadyInHist = false;
var i = 0;
// iterate over the current history and check if the term is
// already there
for (i = 0; i < numHistItems; i++) {
if (term == historyMenu.childNodes[i].getAttribute("label")) {
alreadyInHist = true;
}
}
// add to history
if (!alreadyInHist) {
var myMenuItem = document.createElement("menuitem");
myMenuItem.setAttribute("label", term);
myMenuItem.setAttribute("oncommand", "googlebarAutoSearch(event);");
if (numHistItems <= 0) {
historyMenu.appendChild(myMenuItem);
}
else {
historyMenu.insertBefore(myMenuItem, historyMenu.childNodes[0]);
}
numHistItems++;
if (!ignorePref) {
googlebarAddToHistoryPref(term);
}
// if too many items have been added then remove extra items from the bottom
if (numHistItems > maxHistCnt) {
var numToRemove = numHistItems - maxHistCnt;
// iterate over the current history and remove any extraneous items
for (i = 1; i <= numToRemove; i++) {
historyMenu.removeChild(historyMenu.lastChild);
}
googlebarRefreshHistoryPref();
}
}
}
function googlebarAddToHistoryPref(term)
{
// This function adds the string "term" to the search
// history preference *only* if the option to save
// search history is selected.
//
// This function should only be called after it has
// been established that this item is not already
// in the list of items (see googlebarAddToHistory)
// otherwise there may be duplicate items added to
// the history. There could be a check to see whether
// it exists here as well to prevent this problem
// but it doesn't appear to be necessary at this point
// since this function is only called from within the
// googlebarAddToHistory function.
//
// Another potential problem that should be addressed
// is to check whether or not the || delimeter is
// contained in the search term, if it is then it will
// cause a problem when the history is reloaded.
if (historyOption) {
var sHistory = "";
var sSearch = term;
if (!sSearch) {
return;
}
try {
sHistory = GB_PREF_OBJ.getComplexValue("history", GB_STRING_FLAG).data;
}
catch(e) {
myGooglebarUtil.logMessage("\nHistory get pref err\n" + e );
sHistory = GB_PREF_OBJ.setCharPref("history", "placeholder");
}
if (sHistory) {
sHistory = sHistory + sep + sSearch;
}
else {
sHistory = sSearch;
}
var string = new GB_STRING_CONSTRUCTOR;
string.data = sHistory;
GB_PREF_OBJ.setComplexValue("history", GB_STRING_FLAG, string);
}
}
function googlebarRefreshHistoryPref()
{
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
var historyMenu = critBox.childNodes.item(0);
var numHistItems = historyMenu.childNodes.length;
// sync up the history preference with the new list
GB_PREF_OBJ.setCharPref("history", "");
for (i = numHistItems - 1; i >= 0; i--) {
googlebarAddToHistoryPref(historyMenu.childNodes[i].getAttribute("label"));
}
}
// XXX
function googlebarClearHistory(aflag)
{
// introduced a parm to indicate whether to clear the critBox and search buttons
// true when called by user, false when used otherwise.
// This function removes all items from the search
// history (both history pref and popup menu)
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
if (!critBox) {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.googlebarClearHistory.1"));
return;
}
var saveCurrCrit = critBox.value;
var historyMenu = critBox.childNodes.item(0);
var numHistItems = historyMenu.childNodes.length;
// iterate over the current history and remove each item
for (var i = numHistItems - 1; i >= 0; i--) {
historyMenu.removeChild(historyMenu.childNodes[i]);
}
// next clear all the term buttons, the input field
// (by setting selected index to -1), and history pref
googlebarClearTerms();
critBox.selectedIndex = -1;
GB_PREF_OBJ.setCharPref("history", "");
// When the history is cleared all highlighting must be removed
myGooglebarHighlight.checkHighlight("");
// some people want this cleared, bug 6430, 6462
// so... when invoked by user actions, we don't restore it
// only invoked in the main pulldown menu at present.
if(!aflag){
if(saveCurrCrit)
critBox.value=saveCurrCrit;
googlebarAddTerm(saveCurrCrit);
}
}
function googlebarAddTerm(term)
{
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
var mySearchTermBox = myGooglebarUtil.getElement("googlebarSearchTerms");
var mySearchTermMenu = myGooglebarUtil.getElement("searchterms-menu");
var mySearchTermPopup = myGooglebarUtil.getElement("searchterms-popup");
var myTerms = googlebarFindTerms(term);
var tempNode, tempValue;
var searchTermWidth = 0;
var availableWidth = googlebarAvailableWidth();
mySearchTermBox.setAttribute("googlebaroverflow",false);
var overflow = false;
for (var i = 0; i < myTerms.length; i++) {
tempNode = document.createElement("text");
tempNode.setAttribute("value", myTerms[i]);
//tempNode.setAttribute("className", "googleBarSearchTerm");
tempNode.className = "googleBarSearchTerm";
tempValue = myTerms[i].replace(/\\/, "\\\\");
tempNode.setAttribute("onclick", "googlebarFindInPage(\"" + tempValue + "\" \,event \)");
if (myGooglebarHighlight.isHighlightOn()) {
// for some reason, the following line does not work (the style attribute is set
// but not honored by mozilla), so we have to use a global class
// RF - 2005/01/25
// the style seems to be working in newer versions of firefox and mozilla
// and we want to use the new modifiable array of colors and not the predetermined
// styles in the stylesheet if at all possible. this likely needs testing.
// would be nice to not have to enumerate all 120+ new colors as styles in the
// stylesheet if at all possible.
//
// tempNode.className = "googleBarSearchTerm coloredSearchTerm"+(i%10);
tempNode.setAttribute("style", "background-color:" + myGooglebarHighlight.getTermColors()[i%10]);
tempNode.className = "googleBarSearchTerm";
}
mySearchTermBox.appendChild(tempNode);
searchTermWidth = mySearchTermBox.boxObject.width;
// check if buttons fit, if not, remove the last button
// and add it to the overflow menu
if (searchTermWidth > availableWidth) {
mySearchTermPopup.appendChild(tempNode);
mySearchTermMenu.setAttribute("hidden",false);
overflow = true;
mySearchTermBox.setAttribute("googlebaroverflow",true);
}
else {
if (mySearchTermBox.getAttribute("googlebaroverflow")=="false") {
mySearchTermMenu.setAttribute("hidden",true);
}
}
}
if (myTerms.length > 0) {
myGooglebarUtil.getElement("highlight-button").setAttribute("disabled", false);
}
}
function googlebarCheckSearchbuttons()
{
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
googlebarClearTerms();
googlebarAddTerm(critBox.value);
}
function googlebarAvailableWidth()
{
// This function returns the width which is available for the
// search term buttons
var width=0;
width += myGooglebarUtil.getElement("google-menu").parentNode.boxObject.width;
width -= myGooglebarUtil.getElement("google-menu").boxObject.width;
width -= myGooglebarUtil.getElement("search-textbox").boxObject.width;
width -= myGooglebarUtil.getElement("resize-splitter").boxObject.width;
width -= myGooglebarUtil.getElement("googlebar-buttons").boxObject.width;
return width;
}
function googlebarClearCrit()
{
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
critBox.value = "";
}
function googlebarClearTerms()
{
var termBox = myGooglebarUtil.getElement("googlebarSearchTerms");
var termPopup = myGooglebarUtil.getElement("searchterms-popup");
for (var numTerms = termBox.childNodes.length; numTerms > 0; numTerms--) {
termBox.removeChild(termBox.childNodes[0]);
}
for (numTerms = termPopup.childNodes.length; numTerms > 0; numTerms--) {
termPopup.removeChild(termPopup.childNodes[0]);
}
termBox.setAttribute("googlebaroverflow",false);
}
function googlebarUp(event)
{
var mode;
var win = window._content.document;
var upContainer = myGooglebarUtil.getElement("up-dir-popup");
if (upContainer && upContainer.childNodes.length > 0) {
googlebarDoAction(upContainer.childNodes.item(0).getAttribute("label"), googlebarGetLocFromEvent(event));
}
}
function googlebarHideItem(event)
{
var item = event.target;
var ggbItem = item.getAttribute("googlebaritem");
var ggbButton, ggbMenuitem;
ggbButton = myGooglebarUtil.getElement(ggbItem);
ggbButton.setAttribute("hidden", !item.getAttribute("checked"));
if (hideMenuOption && ggbItem.indexOf("-separate") > 0) {
ggbItem = ggbItem.replace("-separate", "");
ggbMenuitem = myGooglebarUtil.getElement(ggbItem);
if (ggbMenuitem) {
ggbMenuitem.setAttribute("hidden", item.getAttribute("checked"));
}
}
if (inPrefs) {
googlebarGoPopupMenus(inPrefs);
}
updateSeparators();
googlebarCheckSearchbuttons();
}
function googlebarOrdinalUpdater(event) {
var lockOrdinals = event && event.target.getAttribute("checked") == "true";
var lockButton = myGooglebarUtil.getElement("OrderLockButtonItem");
if (lockButton) {
lockButton.setAttribute("checked", lockOrdinals);
}
}
function googlebarOrdinals(event, inPref)
{
if (GB_PREF_OBJ.getBoolPref("lockOrdinals")) {
lockOrdinalOrder();
}
else {
unlockOrdinalOrder();
}
}
function googlebarLabelUpdater(event) {
var showLabels = event && event.target.getAttribute("checked") == "true";
var showButton = myGooglebarUtil.getElement("LabelsButtonItem");
if (showButton) {
showButton.setAttribute("checked", showLabels);
}
}
function googlebarLabels()
{
if (GB_PREF_OBJ.getBoolPref("showLabels")) {
googlebarLabelsOn();
}
else {
googlebarLabelsOff();
}
}
function googlebarLabelsOn()
{
var container = myGooglebarUtil.getElement("googlebar-buttons");
var containerButtons = container.getElementsByTagName("toolbarbutton");
for (var i = 0; i < containerButtons.length; i++) {
containerButtons[i].setAttribute("label", containerButtons[i].getAttribute("buttonlabel"));
myGooglebarUtil.updateClass(containerButtons[i], 0, "button-labeled");
}
}
function googlebarLabelsOff()
{
var container = myGooglebarUtil.getElement("googlebar-buttons");
var containerButtons = container.getElementsByTagName("toolbarbutton");
for (var i = 0; i < containerButtons.length; i++) {
containerButtons[i].removeAttribute("label");
myGooglebarUtil.updateClass(containerButtons[i], 0, containerButtons[i].getAttribute("buttonclass"));
}
}
function googlebarFindInPage(str, evt)
{
/* This is shamelessly taken from Firebird findUtils.js */
var found = false;
var focusedWindow = document.commandDispatcher.focusedWindow;
if (!focusedWindow || focusedWindow == window)
focusedWindow = window._content;
var findInst = getBrowser().webBrowserFind;
var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
findInFrames.rootSearchFrame = window._content;
findInFrames.currentSearchFrame = focusedWindow;
// setup the find instance
findInst.searchString = str;
if(evt)
{
// we hardcode the search options here with what seems to make most sense
findInst.searchFrames = true;
findInst.matchCase = evt.ctrlKey;
findInst.wrapFind = true;
findInst.entireWord = evt.altKey;
findInst.findBackwards = evt.shiftKey;
if(findInst.entireWord)
findInst.searchString = ' ' + str + ' ';
}
found = findInst.findNext();
if (!found) {
alert('"' + str + '" ' + myGooglebarUtil.getElement("bundle_googlebar").getString("gb.notfound"));
}
}
function updateUp()
{
if (!window._content.document) {
return;
}
var currentAddy = (queryStringOption) ? window._content.document.location.href.split("?")[0] : window._content.document.location.href;
var arCurrentAddy = currentAddy.split("/");
var tempNode = false;
var curPath = false;
var i;
// Remove old instances
var upContainer = myGooglebarUtil.getElement("up-dir-popup");
for (i = upContainer.childNodes.length - 1; i >= 0; i--) {
upContainer.removeChild(upContainer.childNodes.item(i));
}
// Add new instances
for (i = arCurrentAddy.length - 1; i > 2; i--) {
if (arCurrentAddy[i].length) {
curPath = myGooglebarUtil.buildUrl(arCurrentAddy, i);
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", curPath);
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "upGo(event, '" + curPath + "'); event.preventBubble();");
tempNode.setAttribute("tooltiptext", curPath);
upContainer.appendChild(tempNode);
}
}
// If we are not at the default web host (www) then add that
// host to the bottom of the list as Google toolbar does
//
// e.g. toolbar.google.com has www.google.com listed on "up" popup menu
if (arCurrentAddy.length >= 3)
{
var currentHost = arCurrentAddy[2];
var arHost = currentHost.split(".");
var wwwHost;
// Assumes somthing like this cs.insertschoolhere.edu, up converts to www.insertschoolhere.edu
if (arHost.length == 3 && arHost[0] != "www") {
wwwHost = arCurrentAddy[0] + "//www" + "." + arHost[1] + "." + arHost[2] + "/";
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", wwwHost);
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "upGo(event, '" + wwwHost + "'); event.preventBubble();");
tempNode.setAttribute("tooltiptext", wwwHost);
upContainer.appendChild(tempNode);
}
// Assumes somthing like this www.cs.insertschoolhere.edu, up converts to www.insertschoolhere.edu
else if (arHost.length == 4 && arHost[0] == "www") {
wwwHost = arCurrentAddy[0] + "//www" + "." + arHost[2] + "." + arHost[3] + "/";
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", wwwHost);
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "upGo(event, '" + wwwHost + "'); event.preventBubble();");
tempNode.setAttribute("tooltiptext", wwwHost);
upContainer.appendChild(tempNode);
}
}
if (upContainer.childNodes.length > 0) {
myGooglebarUtil.getElement("up-dir-button").setAttribute("disabled", false);
}
else {
myGooglebarUtil.getElement("up-dir-button").setAttribute("disabled", true);
}
}
function updateUniv()
{
window._content.document.location = "http://www.google.com/options/universities.html";
populateUniv = true;
// setTimeout("reallyUpdateUniv()", 2000);
}
function reallyUpdateUniv()
{
populateUniv = false;
var univID = "univ-popup";
var univMenu;
var univPopup;
// Remove old instances
var univContainer = myGooglebarUtil.getElement(univID);
for (var i = 3; i < univContainer.childNodes.length; i++) {
univMenu = univContainer.childNodes.item(i);
univPopup = univMenu.childNodes.item(0);
for (var j = univPopup.childNodes.length - 1; j >= 0; j--) {
univPopup.removeChild(univPopup.childNodes.item(j));
}
}
var doc = window._content.document.documentElement;
var aElems = doc.getElementsByTagName("A");
var aData;
var aHref;
var startsWith;
var tempNode;
for (var k = 0; k < aElems.length; k++) {
aHref = aElems[k].getAttribute("href");
if (aHref) {
if (/^\s*http:\/\/www.google.com\/univ\/(.*)/i.test(aHref)) {
aData = aElems[k].firstChild.data;
aData = aData.replace(/\s+/g, " ");
// aData = data.replace(/[\t\n\r ]+/g, " ");
startsWith = aData.substring(0, 1).toLowerCase();
univPopup = myGooglebarUtil.getElement(univID + "-" + startsWith);
if (univPopup) {
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", aData);
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "setUniv('" + aHref + "', '" + aData + "'); event.preventBubble();");
tempNode.setAttribute("tooltiptext", aHref);
univPopup.appendChild(tempNode);
}
}
}
}
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.univ.done"));
}
function setUniv(url, name)
{
var univBtn;
univBtn = myGooglebarUtil.getElement("univ-button");
univBtn.removeAttribute("oncommand");
univBtn.setAttribute("onclick", "if (event.button == 1) { univGo(event, '" + url + "') }");
univBtn.setAttribute("oncommand", "univGo(event, '" + url + "');");
univBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.univ") + " - " + name);
university = url;
GB_PREF_OBJ.setCharPref("university", url);
GB_PREF_OBJ.setCharPref("universityName", name);
}
function univGo(event)
{
if (!university) {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.univ.none"));
}
else {
googlebarSearch(event, "university");
}
}
function upGo(event, addy)
{
googlebarDoAction(addy, googlebarGetLocFromEvent(event));
}
function googlebarCriteriaFocus()
{
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
critBox.focus();
}
function getFocusedElement() {
var ff = document.getElementsByAttribute("focused",true);
return ff.length ? ff[0] : null;
}
// Stateful Show/Focus: interact with the GoogleBar given its current state
// using a single keyboard shortcut. The possible state transitions are
//
// - If the toolbar is hidden, toggle (show) it and focus on the criteria box
//
// - If the criteria box is in focus and ...
// - ... it has no text, fill in and select a default tooltip
// - ... it has less than all of its text selected, select all its text
// - ... it has all of its text selected, toggle (hide) the toolbar
//
// - If the criteria box is blurred, then focus on it
//
// Before focus is given to the criteria box, the element with the current
// focus is saved. When the toolbar is then later hidden, focus is restored
// to that saved element.
function googlebarStatefulShowFocus() {
var googlebar = myGooglebarUtil.getElement( "googlebar" );
var critBox = myGooglebarUtil.getElement( "googlebarCriteria" );
if( googlebar.hidden ) {
gStatefulPrevFocus = getFocusedElement();
goToggleToolbar( "googlebar", "cmd_googlebarShowHide" );
critBox.focus();
} else if( critBox.getAttribute("focused") ) {
if( critBox.inputField.textLength == 0 ) {
critBox.value = "GoogleBar \"Enter your search text\"";
critBox.inputField.select();
} else {
var curClickStart = critBox.inputField.selectionStart;
var curClickEnd = critBox.inputField.selectionEnd;
var curSelSize = curClickEnd - curClickStart;
if( curSelSize < critBox.inputField.textLength ) {
critBox.inputField.select();
} else {
if( gStatefulPrevFocus != null ) { gStatefulPrevFocus.focus(); }
else { window.content.focus(); }
goToggleToolbar( "googlebar", "cmd_googlebarShowHide" );
}
}
} else {
gStatefulPrevFocus = getFocusedElement();
critBox.focus();
}
}
function googlebarCriteriaSelect(event)
{
if (!GB_PREF_OBJ.getBoolPref("autoselectoption")) { return; }
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
var ePt = critBox.inputField.textLength;
var curClickStart = critBox.inputField.selectionStart;
var curClickEnd = critBox.inputField.selectionEnd;
var curSelSize = curClickEnd - curClickStart;
if (event && ePt > 0) {
switch(event.type) {
case "dblclick":
if (!boolCritSelected) {
critBox.inputField.select();
boolCritSelected = true;
}
else {
critBox.inputField.setSelectionRange(curClickStart, curClickEnd);
boolCritSelected = false;
}
break;
case "focus":
if (critIgnoreFocus) {
critIgnoreFocus = false;
}
else {
if (boolCritSelected) {
if (hkeytgl) {
critBox.inputField.setSelectionRange(0, 0 );
boolCritSelected = false;
}
else {
critBox.inputField.select();
}
}
else {
critBox.inputField.select();
boolCritSelected = true;
}
}
break;
case "mousedown":
if (critBox.getAttribute("focused")) {
critIgnoreClick = true;
}
else {
critIgnoreFocus = true;
critIgnoreClick = false;
critBox.inputField.setSelectionRange(0, 0 );
boolCritSelected = true;
}
break;
case "click":
if (!critIgnoreClick && curSelSize == 0) {
critBox.inputField.select();
boolCritSelected = true;
}
break;
default:
break;
}
} // no event or text
}
function googlebarGoPopupMenus(inPrefs)
{
var ggbPopupInUse = myGooglebarUtil.getElement("googlebar-buttons");
googlebarSyncMainPopup("cust-menu", "CustomMenuItem");
googlebarSyncMainPopup("gbsearch-separate", "SearchButtonItem");
googlebarSyncMainPopup("site-separate", "SiteButtonItem");
googlebarSyncMainPopup("lucky-separate", "LuckyButtonItem");
googlebarSyncMainPopup("images-separate", "ImagesButtonItem");
googlebarSyncMainPopup("groups-separate", "GroupsButtonItem");
googlebarSyncMainPopup("directory-separate", "DirectoryButtonItem");
googlebarSyncMainPopup("news-separate", "NewsButtonItem");
googlebarSyncMainPopup("answers-separate", "AnswersButtonItem");
googlebarSyncMainPopup("scholar-separate", "ScholarButtonItem");
googlebarSyncMainPopup("gblogger-separate", "GbloggerButtonItem");
googlebarSyncMainPopup("gb-prefill-separate", "gb-prefillButtonItem");
googlebarSyncMainPopup("gb-options-separate", "OptionsButtonItem");
googlebarSyncMainPopup("catalog-separate", "CatalogButtonItem");
googlebarSyncMainPopup("froogle-separate", "FroogleButtonItem");
googlebarSyncMainPopup("stocks-separate", "StocksButtonItem");
googlebarSyncMainPopup("unclesam-separate", "UnclesamButtonItem");
googlebarSyncMainPopup("viewer-separate", "ViewerButtonItem");
googlebarSyncMainPopup("webquotes-separate", "WebquotesButtonItem");
googlebarSyncMainPopup("dictionary-separate", "DictionaryButtonItem");
googlebarSyncMainPopup("glossary-separate", "GlossaryButtonItem");
googlebarSyncMainPopup("nocalc-separate", "NocalcButtonItem");
googlebarSyncMainPopup("gb-mycountry-separate", "GbmycountryButtonItem");
googlebarSyncMainPopup("gb-mylocal-separate", "GbmylocalButtonItem");
googlebarSyncMainPopup("bsd-separate", "BsdButtonItem");
googlebarSyncMainPopup("linux-separate", "LinuxButtonItem");
googlebarSyncMainPopup("mac-separate", "MacButtonItem");
googlebarSyncMainPopup("microsoft-separate", "MicrosoftButtonItem");
googlebarSyncMainPopup("cached-separate", "CachedButtonItem");
googlebarSyncMainPopup("similar-separate", "SimilarButtonItem");
googlebarSyncMainPopup("backwards-separate", "BackwardsButtonItem");
googlebarSyncMainPopup("translate-separate", "TranslateButtonItem");
googlebarSyncMainPopup("spec-menu", "SpecButtonItem");
googlebarSyncMainPopup("comp-menu", "CompButtonItem");
googlebarSyncMainPopup("univ-button", "UnivButtonItem");
googlebarSyncMainPopup("extras-box", "ExtrasButtonItem");
googlebarSyncMainPopup("info-menu", "InfoButtonItem");
googlebarSyncMainPopup("up-dir-button", "UpDirButtonItem");
googlebarSyncMainPopup("nav-box", "NavButtonItem");
googlebarSyncMainPopup("highlightplus-button", "HighlightPlusButtonItem");
googlebarSyncMainPopup("highlight-button", "HighlightButtonItem");
googlebarSyncMainPopup("googlebarSearchTerms", "SearchTermsButtonItem");
if (inPrefs) { return; }
var element = myGooglebarUtil.getElement("OrderLockButtonItem");
if (element.getAttribute("checked") == "true") {
lockOrdinalOrder();
}
else {
unlockOrdinalOrder();
}
}
function googlebarSyncMainPopup(src, dest)
{
var ggbButtonState = myGooglebarUtil.getElement(src);
var ggbPopupChecked = myGooglebarUtil.getElement(dest);
ggbPopupChecked.setAttribute("checked", !(ggbButtonState.getAttribute("hidden") == "true"));
if (hideMenuOption && src.indexOf("-separate") > 0) {
var ggbItem = src.replace("-separate", "");
var ggbMenuitem = myGooglebarUtil.getElement(ggbItem);
if (ggbMenuitem) {
ggbMenuitem.setAttribute("hidden", !(ggbButtonState.getAttribute("hidden") == "true"));
}
}
}
function googlebarSyncMenuButton(ggbButton, ggbOption)
{
// If there was a previous search selected for the
// menu button and the preference is set to save
// these settings then attempt to restore the
// selection, if possible, otherwise just ignore it
if (!saveLastOption) {
return;
}
var optionValue;
try {
optionValue = GB_PREF_OBJ.getCharPref(ggbOption);
}
catch(e) { myGooglebarUtil.logMessage( "\n" + e + "\n" );
GB_PREF_OBJ.setCharPref(ggbOption, "");
optionValue = "";
}
var menuButton = myGooglebarUtil.getElement(ggbButton);
var separateButton = myGooglebarUtil.getElement(optionValue + "-separate");
if (!menuButton || !separateButton) {
return;
}
menuButton.removeAttribute("oncommand");
menuButton.setAttribute("oncommand", separateButton.getAttribute("oncommand"));
menuButton.setAttribute("buttonclass", separateButton.getAttribute("buttonclass"));
menuButton.setAttribute("class", separateButton.getAttribute("class"));
menuButton.setAttribute("buttonlabel", separateButton.getAttribute("buttonlabel"));
menuButton.setAttribute("tooltiptext", separateButton.getAttribute("tooltiptext"));
if (separateButton.getAttribute("label")) {
menuButton.setAttribute("label", separateButton.getAttribute("label"));
}
}
function googlebarCriteriaTooltip()
{
var critBox = myGooglebarUtil.getElement("googlebarCriteria");
if (critBox.value) {
critBox.tooltipText = critBox.value;
}
else {
critBox.tooltipText = critBox.statusText;
}
}
function srchFlipflop()
{
var ggbsrchterms = myGooglebarUtil.getElement("googlebarSearchTerms");
var searchTermMenu = myGooglebarUtil.getElement("searchterms-menu");
ggbsrchterms.setAttribute("hidden", !ggbsrchterms.hidden );
// when we are overflowing, set the hidden status of the overflow
// menu accordingly
if (ggbsrchterms.getAttribute("googlebaroverflow")=="true") {
searchTermMenu.setAttribute("hidden", ggbsrchterms.hidden );
}
// when the search buttons were unhidden, we have to check
// if they fit
if (!ggbsrchterms.hidden) {
googlebarCheckSearchbuttons();
}
return true;
}
function setGoogleContextMenu(inPrefs)
{
var cntxtmnu = myGooglebarUtil.getElement('context-googlebar-doc-items');
var cntxtmnu_sep = myGooglebarUtil.getElement('context-sep-google');
var cntxtmnuopt;
if (inPrefs) {
cntxtmnuopt = !myGooglebarUtil.getElement('contextmenuoption').checked;
}
else {
cntxtmnuopt = !GB_PREF_OBJ.getBoolPref("contextmenuoption");
}
cntxtmnu.setAttribute('hidden', cntxtmnuopt);
cntxtmnu_sep.setAttribute('hidden', cntxtmnuopt);
}
function cntrySfxsInit()
{
for (var i = 0; myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country." + i) != "endoflist"; i++) {
cntrySfxs[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country." + i);
}
}
function mycntrySfxsInit()
{
for (var i = 0; myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mycountry." + i) != "endoflist"; i++) {
mycntrySfxs[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mycountry." + i);
}
}
function mylangSfxsInit()
{
for (var i = 0; myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mylang." + i) != "endoflist"; i++) {
mylangSfxs[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mylang." + i);
}
}
function cntryNewsSfxsInit()
{
for (var i = 0; myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country." + i) != "endoflist"; i++) {
cntryNewsSfxs[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country." + i);
cntryNewsSites[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country.site." + i);
}
}
function selectGgbCountry(cntry)
{
if (cntry) {
GB_PREF_OBJ.setIntPref("country2Search", cntry);
cntry2SrchIx = cntry;
cntry2Srch = cntrySfxs[cntry2SrchIx];
}
else {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country.none"));
}
}
function selectGgbCountryNews(cntry)
{
if (cntry) {
GB_PREF_OBJ.setIntPref("countryNews2Search", cntry);
cntryNews2SrchIx = cntry;
cntryNews2Srch = cntryNewsSfxs[cntryNews2SrchIx];
cntryNewsSite = cntryNewsSites[cntryNews2SrchIx];
}
else {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country.none"));
}
}
function selectGgbMyCountry(cntry)
{
if (cntry) {
GB_PREF_OBJ.setIntPref("mycountry2Search", cntry);
mycntry2SrchIx = cntry;
mycntry2Srch = mycntrySfxs[mycntry2SrchIx];
}
else {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country.none"));
}
}
function selectGgbMyLang(cntry)
{
if (cntry) {
GB_PREF_OBJ.setIntPref("mylang2Search", cntry);
mylang2SrchIx = cntry;
mylang2Srch = mylangSfxs[mylang2SrchIx];
}
else {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.lang.none"));
}
}
function setMaxHistCnt(cnt)
{
if (cnt) {
GB_PREF_OBJ.setIntPref("maxHistCnt", cnt);
}
else {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.error.max_hist"));
GB_PREF_OBJ.setIntPref("maxHistCnt", 10);
}
maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
}
function setResultLimit(cnt)
{
if (cnt) {
GB_PREF_OBJ.setIntPref("resultLimit", cnt);
}
else {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.error.result_limit"));
GB_PREF_OBJ.setIntPref("resultLimit", -1);
}
resultLimit = GB_PREF_OBJ.getIntPref("resultLimit");
}
function googlebarOpenPrefs()
{
if (myGooglebarUtil.isInFirefox()) {
window.openDialog('chrome://googlebar/content/googlebarPrefDialog.xul', 'Googlebar Options', 'chrome');
}
else {
goPreferences('googlebarItem', 'chrome://googlebar/content/pref/pref-googlebar1.xul', 'googlebarItem');
}
}
function googlebarOpenGooglePrefs()
{
window._content.document.location = 'http://www.google.' + cntry2Srch + '/preferences';
}
function googlebarUpdateParent(event)
{
if (!saveLastOption) {
return;
}
var menuButton = event.target.parentNode.parentNode;
var separateButton = myGooglebarUtil.getElement(event.target.getAttribute("id") + "-separate");
menuButton.removeAttribute("oncommand");
menuButton.setAttribute("oncommand", separateButton.getAttribute("oncommand"));
menuButton.setAttribute("buttonclass", separateButton.getAttribute("buttonclass"));
menuButton.setAttribute("class", separateButton.getAttribute("class"));
menuButton.setAttribute("buttonlabel", separateButton.getAttribute("buttonlabel"));
menuButton.setAttribute("tooltiptext", separateButton.getAttribute("tooltiptext"));
if (separateButton.getAttribute("label")) {
menuButton.setAttribute("label", separateButton.getAttribute("label"));
}
if (menuButton.getAttribute("id") == "comp-menu") {
GB_PREF_OBJ.setCharPref("lastCompSearch", event.target.getAttribute("id"));
}
else if (menuButton.getAttribute("id") == "cust-menu") {
GB_PREF_OBJ.setCharPref("lastCustSearch", event.target.getAttribute("id"));
}
else if (menuButton.getAttribute("id") == "info-menu") {
GB_PREF_OBJ.setCharPref("lastInfoSearch", event.target.getAttribute("id"));
}
else if (menuButton.getAttribute("id") == "spec-menu") {
GB_PREF_OBJ.setCharPref("lastSpecSearch", event.target.getAttribute("id"));
}
else {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.googlebarUpdateParent.1") + menuButton.getAttribute("id"));
}
}
function googlebarResetParents(event)
{
if (event.target.checked)
return;
googlebarResetParent(myGooglebarUtil.getElement('comp-menu'));
googlebarResetParent(myGooglebarUtil.getElement('cust-menu'));
googlebarResetParent(myGooglebarUtil.getElement('info-menu'));
googlebarResetParent(myGooglebarUtil.getElement('spec-menu'));
}
function googlebarResetParent(menuButton)
{
menuButton.removeAttribute("oncommand");
menuButton.setAttribute("oncommand", "googlebarShowPopup(event)");
menuButton.setAttribute("buttonclass", menuButton.getAttribute('id'));
menuButton.setAttribute("class", menuButton.getAttribute('id') + " dragbordernone");
menuButton.setAttribute("buttonlabel", menuButton.getAttribute('originallabel'));
menuButton.setAttribute("tooltiptext", menuButton.getAttribute('originaltooltip'));
if (menuButton.getAttribute("label")) {
menuButton.setAttribute("label", menuButton.getAttribute('originallabel'));
}
}
function googlebarShowPopup(event)
{
if ((event.target.getAttribute("type") == "menu" || event.target.getAttribute("type") == "menu-button") && event.target.firstChild)
{
event.target.firstChild.showPopup();
}
}
function googlebarUpdateNewWindow()
{
// Only need to update from another window once
// Get out of here if that has already happened
if (openerUpdated)
return;
// This method is used to update the current search terms
// from another window. This should happen when
// 1. a new window is opened for the first time called from googlebarDisplayCheck()
// 2. a google search result
var otherCriteria = null;
var otherHighlight = null;
var thisCriteria = myGooglebarUtil.getElement("googlebarCriteria");
// If this window was opened from another window, just use
// the criteria from the opener
if (window.opener) {
otherCriteria = window.opener.document.getElementById("googlebarCriteria");
otherHighlight = window.opener.document.getElementById("highlight-button");
if (otherCriteria){
thisCriteria.value = otherCriteria.value;
openerUpdated = true;
myGooglebarUtil.logMessage('Updated criteria from window opener');
}
}
else {
// window had not opener, so get the criteria from somewhere else
var openwindows = GB_WINDOW_SVC.getEnumerator(null);
// check all open windows for googlebarCriteria
// this will always get the search terms of the last window
// in the list, this might not be the last window which was
// selected, so this might not always give the expected result
while (openwindows.hasMoreElements()) {
var win = openwindows.getNext();
if (win != window) {
otherCriteria = win.document.getElementById("googlebarCriteria");
otherHighlight = win.document.getElementById("highlight-button");
if (otherCriteria) {
// Does this work?
thisCriteria.value = otherCriteria.value;
openerUpdated = true;
myGooglebarUtil.logMessage('Updated criteria from another window containing a googlebar');
break;
}
}
}
}
if (otherHighlight && otherHighlight.getAttribute("activated") == "true") {
myGooglebarHighlight.highLightInPage("on");
}
}
function check4NewInstall() {
if(gbCheck4BrowserWindows()){
// Look for a zero byte file - googlebarIsNew
// This file is only needed if someone changes or adds prefs
// It puts the responsibility on the user for prefs that point to old
// meanings. Unless someone want to make a versioned table of prefs :)
const kDirServiceCID = Components.ID("{f00152d0-b40b-11d3-8c9c-000064657374}");
const nsIProperties = Components.interfaces.nsIProperties;
const nsIFileIID = Components.ID("{c8c0a080-0868-11d3-915f-d9d889d48e3c}");
var cTyp = retv = 0;
var dSrv = Components.classes['@mozilla.org/file/directory_service;1'].createInstance();
dSrv = dSrv.QueryInterface(Components.interfaces.nsIProperties);
var dSrvI = dSrv.get("AChrom", Components.interfaces.nsIFile);
dSrvI.append("googlebar");
dSrvI.append("content");
dSrvI.append("googlebarIsNew");
retv=dSrvI.exists();
if(retv) {
cTyp ="AChrom";
}
else {
dSrvI = dSrv.get("UChrm", Components.interfaces.nsIFile);
dSrvI.append("googlebar");
dSrvI.append("content");
dSrvI.append("googlebarIsNew");
retv=dSrvI.exists();
if(retv)
cTyp ="UChrm";
}
if(!cTyp){
// myGooglebarUtil.logMessage("googlebarIsNew NOT Found in any chrome location\n");
// Here we can set a pref that is really a flag
// that then works for every tab and window.
// that we have checked for any new installation.
return;
}
// returns our c:\\windows\stuff as file:///c:/windows
// not used yet, but it may be later
// var thisUri = getFileUri(dSrvI);
if(cTyp=="UChrm"){
myGooglebarUtil.logMessage("Found googlebarIsNew in user profile\n");
// Tell the user to check their preferences,
// because they are probably there but have changed meaning.
if(confirm(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.check4NewInstall.1") )) {
googlebarOpenPrefs();
// delete the triggerfile
dSrvI.remove(true) ;
}
else
if(!confirm(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.check4NewInstall.2") )) {
// delet the triggerfile
dSrvI.remove(true) ;
}
} //if(cTyp=="UChrm")
if(cTyp=="AChrom"){
myGooglebarUtil.logMessage("Found googlebarIsNew in system profile\n");
// Tell the user to check their preferences,
// because they are probably there but have changed meaning.
if(confirm(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.check4NewInstall.1") )) {
googlebarOpenPrefs();
// delete the triggerfile
dSrvI.remove(true) ;
}
else
if(!confirm(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.check4NewInstall.2") )) {
// delet the triggerfile
dSrvI.remove(true) ;
}
}//if(cTyp=="AChrom")
}// if we have a browser window...
}
function getFileUri( fpath ){
const nsIFileIID = Components.ID("{c8c0a080-0868-11d3-915f-d9d889d48e3c}");
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var newUri;
// Interface change - ns7 (mozilla 1.0) needs nsIIOService
// latter (mozilla 1.2) needs nsIFileProtocolHandler
if(Components.interfaces.nsIFileProtocolHandler){
var fileHandler =
ios.getProtocolHandler("file")
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
newUri = fileHandler.getURLSpecFromFile(fpath);
} else {
newUri = ios.getURLSpecFromFile(fpath);
}
return newUri;
}
function gbCheck4BrowserWindows() {
// Quicklaunch seems to be a full browser window.
if(GB_WINDOW_SVC.getMostRecentWindow("navigator:browser"))
{
if ("arguments" in window && window.arguments.length > 1 && window.arguments[1])
{
if (window.arguments[1].indexOf("charset=") != -1)
{
var arrayArgComponents = window.arguments[1].split("=");
if (arrayArgComponents)
{
getMarkupDocumentViewer().defaultCharacterSet = arrayArgComponents[1];
}
}
else
if (window.arguments[1].indexOf("turbo=yes") != -1)
{
var gb_turboMode = true;
return false ;
}
} // got a browser window besides quicklaunch
return true ;
} // no browsers
return false;
}
function googlebarIsUnHiding(){
var googlebar = myGooglebarUtil.getElement( "googlebar" );
var currCrit = myGooglebarUtil.getElement("googlebarCriteria").value ;
// If you have some text in the criteria box, updating searchword buttons
// on reappearance is unsightly. The buttons adjust one character at a time.
if(!googlebar.getAttribute("hidden") || googlebar.getAttribute("hidden") == "false")
return;
googlebarClearCrit();
googlebarClearTerms();
goToggleToolbar("googlebar","cmd_googlebarShowHide");
setTimeout("myGooglebarUtil.getElement('googlebarCriteria').focus()", 100);
// let's just blank it out... for now.
currCrit = "";
myGooglebarUtil.getElement("googlebarCriteria").value = currCrit;
googlebarAddTerm(currCrit);
}
function googlebarIsHiding(){
var googlebar = myGooglebarUtil.getElement("googlebar");
if(googlebar.getAttribute("hidden") && googlebar.getAttribute("hidden") == "true")
return;
goToggleToolbar('googlebar','cmd_googlebarShowHide');
setTimeout("window.document.getElementById('urlbar').focus()", 0);
}
function gbDoNonSearch(event, searchType, searchParams) {
// a place to do non Google searches explicitly
// return true if we find anything we can handle, whether we actually do anything
// with it is not relevant, just whether we should keep going through the main search
// processing
if( searchType == 'gb-prefill' ) {
if(myGooglebarUtil.isInFirefox()) {
alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.gbDoNonSearch.1"));
}
var gbformsArray = content.document.forms;
if ( !gbformsArray ) {
return true ;
}
if (event.button == 1) {
var gbwallet = Components.classes["@mozilla.org/wallet/wallet-service;1"].getService(Components.interfaces.nsIWalletService);
gbwallet.WALLET_RequestToCapture( window._content );
}
else {
if( event.ctrlKey || event.shiftKey || event.altKey ) {
formPrefill();
// any modifier key bring up the forms dialog if an unknown form,
// known forms it will fill in if you told it to do so previously
// do we want to touch passwords and the security issues.
}
else
var walletService = Components.classes["@mozilla.org/wallet/wallet-service;1"].getService(Components.interfaces.nsIWalletService);
try { walletService.WALLET_Prefill(true, window._content); }
catch(e) { }
}
return true;
}
return false; // we found nothing to handle here, keep going with main googlebarSearch
}
function gbLook4URL(event, searchType, searchParams)
{
var criteria = myGooglebarUtil.getElement("googlebarCriteria");
var testIndx;
var tempval = criteria.value;
try { testIndx = tempval.search(/^(http|https|ftp|file|irc|mailto|news|nntp):/i); }
catch(e)
{
testIndx = -1;
} // nothing
if(testIndx != -1)
return 1;
else
try { testIndx = tempval.search(/^(www\.)/i); }
catch(e)
{ /* XXX replace the prefix to http:// */
testIndx = -1;
}
if(testIndx != -1) {
var newval = "http://" + criteria.value;
criteria.value = newval;
return 1;
}
else
return 0;
// we didn't find it, or there was a general error
}
function gbprompt(msg, initial, parent, title)
{
var PROMPT_CTRID = "@mozilla.org/embedcomp/prompt-service;1";
var nsIPromptService = Components.interfaces.nsIPromptService;
var ps = Components.classes[PROMPT_CTRID].getService(nsIPromptService);
if (!parent)
parent = window;
if (!title)
title = MSG_PROMPT; // probably just in seamonkey
rv = { value: initial };
if (!ps.prompt (parent, title, msg, rv, null, {value: null}))
return null;
return rv.value;
}
function googlebarOrderMenu(menuName, startIndex) {
if (!startIndex)
startIndex = 0;
var i, j;
var menuElement = myGooglebarUtil.getElement(menuName);
var unorderedItems = menuElement.getElementsByTagName("menuitem");
var orderedItems = new Array(unorderedItems.length - startIndex);
for (i = startIndex; i < unorderedItems.length; i++) {
orderedItems[i - startIndex] = unorderedItems[i];
}
var tempItem;
// Quick bubble sort - list is short so performance doesn't matter much
for (i = orderedItems.length - 1; i > 0; i--) {
for (j = 0; j < i; j++) {
if (orderedItems[j].getAttribute("label") > orderedItems[j + 1].getAttribute("label")) {
tempItem = orderedItems[j + 1];
orderedItems[j + 1] = orderedItems[j];
orderedItems[j] = tempItem;
}
}
}
for (i = 0; i < orderedItems.length; i++) {
orderedItems[i].setAttribute("ordinal", i + startIndex);
}
menuElement.setAttribute("hidden", "true");
menuElement.setAttribute("hidden", "false");
}
function googlebarGetCustomList()
{
var customList = new Array();
var custPopup = myGooglebarUtil.getElement('cust-popup');
for (var i = custPopup.childNodes.length - 1; i >= 0; i--) {
customList.push(custPopup.childNodes[i].getAttribute('id'));
}
return customList;
}
function googlebarUpdateCustomList(customList)
{
if (!customList)
customList = [];
var custPopup = myGooglebarUtil.getElement('cust-popup');
var i;
for (i = custPopup.childNodes.length - 1; i >= 0; i--) {
custPopup.removeChild(custPopup.childNodes[i]);
}
var customString = "";
for (i = 0; i < customList.length; i++) {
var custChild = myGooglebarUtil.getElement(customList[i]).cloneNode(false);
custPopup.appendChild(custChild);
if (i > 0) {
customString += sep;
}
customString += custChild.getAttribute('id');
}
var string = new GB_STRING_CONSTRUCTOR;
string.data = customString;
GB_PREF_OBJ.setComplexValue("customList", GB_STRING_FLAG, string);
}
///////////////////////////////////////////////////////////////////////////////
////////////////////////////// Experimental ///////////////////////////////////
function googlebarRemoveListener() {
window.getBrowser().removeProgressListener(myGooglebarLocListener);
}
function googlebarSuggest(searchString)
{
if (!GB_PREF_OBJ.getBoolPref("googleSuggest"))
return;
if (myGooglebarUtil.trimString(searchString) == "")
return;
var searchURL = 'http://www.google.com/complete/search?hl=en&js=true&qu=' + searchString;
myGooglebarUtil.getElement('googleSuggestFrame').setAttribute('src', searchURL);
setTimeout("googlebarUpdateSuggest()", 500);
}
function googlebarUpdateSuggest()
{
try {
var html = myGooglebarUtil.getElement('googleSuggestFrame').contentDocument;
var text = html.getElementsByTagName('BODY')[0].firstChild.nodeValue;
var cmd = text.replace(/\s*sendRPCDone\(frameElement,\s*/, 'googlebarDisplaySuggest(');
eval(cmd);
}
catch (e) {
// Do something here, at some point
}
}
function googlebarSearchSuggest(event, searchString)
{
myGooglebarUtil.getElement("googlebarCriteria").value = searchString;
googlebarClearTerms();
googlebarAddTerm(searchString);
myGooglebarHighlight.delayHighlight();
googlebarSearch(event);
}
function googlebarDisplaySuggest(searchString, labelArray, resultArray, otherArray)
{
var suggestPop = myGooglebarUtil.getElement("googlebarSuggestMenu");
var ndx;
var tempNode;
// clean up all of the popup menu items
for (ndx = suggestPop.childNodes.length - 1; ndx >= 0; ndx--) {
suggestPop.removeChild(suggestPop.childNodes[ndx]);
}
// add suggest items to the popup menu
for (ndx = 0; ndx < labelArray.length; ndx++) {
tempNode = document.createElement("menuitem");
tempNode.setAttribute("label", labelArray[ndx] + " - " + resultArray[ndx]);
tempNode.setAttribute("class", "menuitem-all");
tempNode.setAttribute("oncommand", "googlebarSearchSuggest(event, '" + labelArray[ndx] + "');");
suggestPop.appendChild(tempNode);
}
suggestPop.showPopup();
}
/*
function googlebarDisplaySuggest(searchString, labelArray, resultArray, otherArray)
{
var display = "";
display += " Google Suggest Result for '" + searchString + "'\n";
display += "-------------------------------------------------\n";
for (var i = 0; i < labelArray.length; i++) {
display += labelArray[i];
display += "\t\t";
display += resultArray[i];
display += "\n";
}
alert(display);
}
*/